import os
current_directory = os.getcwd()
print(current_directory)
/Users/macbookpro/hdd/MSc/Dissertation/multilabeltextclassification
import numpy
numpy.version.version
'1.22.0'
from tensorflow import keras
import tensorflow as tf
from tensorflow.keras.preprocessing.text import Tokenizer
from keras.utils import pad_sequences
from tensorflow.keras.preprocessing import text, sequence
from tensorflow.keras import initializers, regularizers, constraints, optimizers, layers
from tensorflow.python.keras.models import Model, Input
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import GRU, Dense, Input, LSTM, Embedding, Dropout, SpatialDropout1D, Activation, SimpleRNN
from tensorflow.keras.layers import Conv1D, Bidirectional, GlobalMaxPool1D, MaxPooling1D, BatchNormalization, Add, Flatten
from tensorflow.keras.layers import GlobalMaxPooling1D, GlobalAveragePooling1D, concatenate
from tensorflow.keras.optimizers import Adam
#from tensorflow.keras.optimizers import SGD
# For custom metrics
import keras.backend as K
from keras.utils.vis_utils import plot_model
from keras.callbacks import EarlyStopping
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn')
import seaborn as sns
from IPython.display import Image
from tqdm import tqdm
from nltk.corpus import stopwords
from nltk.tokenize import RegexpTokenizer
import os, re, csv, math, codecs
from nltk.tokenize import word_tokenize
import string
import gensim
sns.set_style("whitegrid")
np.random.seed(0)
# Install dependencies
!apt install graphviz
!pip install pydot pydot-ng
!echo "Double check with Python 3"
!python -c "import pydot"
2023-04-01 05:53:17.044359: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt. Please visit http://www.java.com for information on installing Java. Requirement already satisfied: pydot in /Users/macbookpro/opt/anaconda3/lib/python3.9/site-packages (1.4.2) Requirement already satisfied: pydot-ng in /Users/macbookpro/opt/anaconda3/lib/python3.9/site-packages (2.0.0) Requirement already satisfied: pyparsing>=2.1.4 in /Users/macbookpro/opt/anaconda3/lib/python3.9/site-packages (from pydot) (3.0.4) Double check with Python 3
#df1 = pd.read_csv('/Users/macbookpro/hdd/MSc/Dissertation/multilabeltextclassification/githubissuedata2M.csv')
df = pd.read_csv('/Users/macbookpro/hdd/MSc/Dissertation/multilabeltextclassification/githubissuedata.csv')
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 226163 entries, 0 to 226162 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 title 225152 non-null object 1 body 225866 non-null object 2 task 226163 non-null int64 3 bug 226163 non-null int64 4 documentation 226163 non-null int64 5 duplicate 226163 non-null int64 6 enhancement 226163 non-null int64 7 good_first_issue 226163 non-null int64 8 help_wanted 226163 non-null int64 9 invalid 226163 non-null int64 10 question 226163 non-null int64 11 wontfix 226163 non-null int64 12 gitalk 226163 non-null int64 13 priority_medium 226163 non-null int64 14 priority_high 226163 non-null int64 15 feature_request 226163 non-null int64 16 feature 226163 non-null int64 dtypes: int64(15), object(2) memory usage: 29.3+ MB
df.head(10)
| title | body | task | bug | documentation | duplicate | enhancement | good_first_issue | help_wanted | invalid | question | wontfix | gitalk | priority_medium | priority_high | feature_request | feature | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | My Account Paid laptop 1440 resolution Updat... | Case:Distance between Registered email address... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | How to fix sleepimpl warning when ECS credenti... | Prerequisites X Ive searched for previous sim... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | Slider doesnt work on touch devices | DescriptionSlider should work dragging in tou... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | add new labels | DescriptionAdd ui and logic to permanently ad... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | No lib sub folder in Boost folder | Hi I am following thishttps://www.mlpack.org/d... | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 5 | Add license notice to CLI | The CLI is missing the license notice. Theres ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 6 | Should show Powershell or AzureCLI code necess... | There is example output from Powershell and Az... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 7 | tidboperator could not work with kubernetes 1.23 | Bug ReportWhat version of Kubernetes are you ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 8 | Match Live | x Implement game logic x Calculate results ba... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 9 | AngularBug Make current location widget more g... | If youve never submitted an issue to the SORMA... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
# check missing values in the dataset
print('The dataset has', df.isna().sum().sum(), 'missing values in test data.')
# check any duplicate records in the dataset
print('The dataset has', df.duplicated().sum(), 'duplicates in train data.')
The dataset has 1308 missing values in test data. The dataset has 46411 duplicates in train data.
# remove missing values in the dataset
df.dropna(inplace= True)
# remove all duplicate records in the dataset
df.drop_duplicates(inplace= True)
# check missing values in the dataset
print('The dataset has', df.isna().sum().sum(), 'missing values in test data.')
# check any duplicate records in the dataset
print('The dataset has', df.duplicated().sum(), 'duplicates in train data.')
The dataset has 0 missing values in test data. The dataset has 0 duplicates in train data.
# spliting dataset to train and test
from sklearn.model_selection import train_test_split
train_df, test_df = train_test_split(df, test_size=0.2, random_state=25)
print("Train data shape", train_df.shape)
print("Test data shape", test_df.shape)
Train data shape (143145, 17) Test data shape (35787, 17)
fig, ax = plt.subplots(figsize=(10, 6))
fig.suptitle('Correlation Matrix')
sns.heatmap(train_df.corr(), annot=True, cmap="Greens", linewidths=.5, ax=ax);
The correlation figure below shows that Toxic" comments are clearly correlated with both "obscene" and "insult" comments. Interestingly, "toxic" and "severe_toxic" are only weakly correlated. While we can also observe that, "Obscene" comments and "insult" comments are also highly correlated, which makes perfect sense.
Deep Neural Networks input layers make use of input variables to feed the network for training the model. But in this task (experiment), we're dealing with words text. How do we represent these words in order to feed our model?
In our experiment, we used densed representation of those text (comments) and their semanticity together. The advantage of using this approach is the best way for fitting neural networks onto a text data (as in our case), as well as less memory usage compared to other sparse representation approaches.
Two ways to feed embeddings to neural networks:
#Convert text to vectors using keras preprocessing library tools
X_train = train_df["body"].values
X_test = test_df["body"].values
y_train = train_df[["task","bug","documentation","duplicate","enhancement","good_first_issue","help_wanted","invalid","question","wontfix","gitalk","priority_medium","priority_high","feature_request","feature"]].values
y_test = test_df[["task","bug","documentation","duplicate","enhancement","good_first_issue","help_wanted","invalid","question","wontfix","gitalk","priority_medium","priority_high","feature_request","feature"]].values
For the first embedding, we used keras preprocessing (Text Preprocessing) libraries. This class allows to vectorize a text corpus, by turning each text into either a sequence of integers (each integer being the index of a token in a dictionary) or into a vector where the coefficient for each token could be binary, based on word count, based on tf-idf
num_words = 20000 #Max. workds to use per toxic comment
max_features = 200000 #Max. number of unique words in embeddinbg vector
max_len = 500 #Max. number of words per issue bodies to be use
embedding_dims = 128 #embedding vector output dimension
num_epochs = 15 # (before 5)number of epochs (number of times that the model is exposed to the training dataset)
val_split = 0.1
batch_size2 = 256 #(before 32)The **batch size** is the number of training examples in one forward/backward pass.
# In general, larger batch sizes result in faster progress in training, but don't always converge as quickly.
#Smaller batch sizes train slower, but can converge faster. And the higher the batch size, the more memory space you’ll need.
#Issue body Tokenization
tokenizer = tokenizer = Tokenizer(num_words)
tokenizer.fit_on_texts(list(X_train))
#Convert tokenized issue body text to sequnces
X_train = tokenizer.texts_to_sequences(X_train)
X_test = tokenizer.texts_to_sequences(X_test)
# padding the sequences
X_train = pad_sequences(X_train, max_len)
X_test = pad_sequences(X_test, max_len)
print('X_train shape:', X_train.shape)
print('X_test shape: ', X_test.shape)
X_train shape: (143145, 500) X_test shape: (35787, 500)
X_tra, X_val, y_tra, y_val = train_test_split(X_train, y_train, train_size =0.9, random_state=233)
early = EarlyStopping(monitor="val_loss", mode="min", patience=4)
#Writing functions for Precision, Recall, F1-Measure, AUC, mean etc evaluaiton metrics to evaluate the model
#Import necessary libraries
4# demonstration of calculating metrics for a neural network model using sklearn
from sklearn.datasets import make_circles
from sklearn.metrics import accuracy_score
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.metrics import f1_score
from sklearn.metrics import cohen_kappa_score
from sklearn.metrics import roc_auc_score
from sklearn.metrics import confusion_matrix
def precision(y_true, y_pred):
#Calculating precision, a metric for multi-label classification of how many selected items are relevant.
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def recall(y_true, y_pred):
#Calculating recall, a metric for multi-label classification of how many relevant items are selected.
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
#Customized the evaluation to analyse the model in terms of accuracy and mean value accuracy
def mean_pred(y_true, y_pred):
return K.mean(y_pred)
def fbeta_score(y_true, y_pred, beta=1):
'''Calculates the F score, the weighted harmonic mean of precision and recall.
This is useful for multi-label classification, where input samples can be
classified as sets of labels. By only using accuracy (precision) a model
would achieve a perfect score by simply assigning every class to every
input. In order to avoid this, a metric should penalize incorrect class
assignments as well (recall). The F-beta score (ranged from 0.0 to 1.0)
computes this, as a weighted mean of the proportion of correct class
assignments vs. the proportion of incorrect class assignments.
With beta = 1, this is equivalent to a F-measure. With beta < 1, assigning
correct classes becomes more important, and with beta > 1 the metric is
instead weighted towards penalizing incorrect class assignments.
'''
if beta < 0:
raise ValueError('The lowest choosable beta is zero (only precision).')
# If there are no true positives, fix the F score at 0 like sklearn.
if K.sum(K.round(K.clip(y_true, 0, 1))) == 0:
return 0.0
p = precision(y_true, y_pred)
r = recall(y_true, y_pred)
bb = beta ** 2
fbeta_score = (1 + bb) * (p * r) / (bb * p + r + K.epsilon())
return fbeta_score
def auroc(y_true, y_pred):
auc = tf.keras.metrics.AUC(y_true, y_pred)[1]
#auc = tf.metrics.auc(y_true, y_pred)[1]
K.get_session().run(tf.local_variables_initializer())
return auc
def fmeasure(y_true, y_pred):
#Calculates the f-measure, the harmonic mean of precision and recall.
return fbeta_score(y_true, y_pred, beta=1)
fscore = f1score = fmeasure
import nltk
nltk.download('punkt')
nltk.download('stopwords')
[nltk_data] Downloading package punkt to [nltk_data] /Users/macbookpro/nltk_data... [nltk_data] Package punkt is already up-to-date! [nltk_data] Downloading package stopwords to [nltk_data] /Users/macbookpro/nltk_data... [nltk_data] Package stopwords is already up-to-date!
True
issueBodies_lines = list()
lines = train_df['body'].values.tolist()
for line in lines:
tokens = word_tokenize(line)
#convert to lower case
tokens = [w.lower() for w in tokens]
#remove punctuation from each word
table = str.maketrans('', '', string.punctuation)
stripped = [w.translate(table) for w in tokens]
#remove remaining tpkens gthat are not alphabetic
words = [word for word in stripped if word.isalpha()]
#filter out stop words
stop_words = set(stopwords.words('english'))
words = [w for w in words if not w in stop_words]
issueBodies_lines.append(words)
len(issueBodies_lines)
143145
#train word2vec mode
word2VecModel = gensim.models.Word2Vec(sentences=issueBodies_lines, vector_size= embedding_dims, window=5, workers=4, min_count=1)
#vocab size
wors = list(word2VecModel.wv.index_to_key)
print('Vocabulary size: %d' % len(words))
Vocabulary size: 53
#Save the Word2Vec Corpus locally¶
filename = 'issue_embedding_word2vec.txt'
word2VecModel.wv.save_word2vec_format(filename, binary=False)
#Use the Pre-Trained Embedding (Word2Vec) in our models (CNN, and RNN)
word2Vec_embeddings_index = {}
word2vec_file = open(os.path.join('', 'issue_embedding_word2vec.txt'), encoding = "utf-8")
for line in word2vec_file:
values = line.split()
word = values[0]
coefficient = np.asarray(values[1:])
word2Vec_embeddings_index[word] = coefficient
word2vec_file.close()
#vectorize the text samples into a 2D integer tensor
tokenizer_obj = Tokenizer()
tokenizer_obj.fit_on_texts(issueBodies_lines)
sequences = tokenizer_obj.texts_to_sequences(issueBodies_lines)
#pad sequences
word_index = tokenizer_obj.word_index
print('Found %s uniquue tokens.' % len(word_index))
issueBodies_pad = pad_sequences(sequences, maxlen=max_len)
issue_tag = train_df[["task","bug","documentation","duplicate","enhancement","good_first_issue","help_wanted","invalid","question","wontfix","gitalk","priority_medium","priority_high","feature_request","feature"]].values
print('Shape of issue bodies tensor', issueBodies_pad.shape)
print('Shape of issue bodies tensor', issue_tag.shape)
Found 792007 uniquue tokens. Shape of issue bodies tensor (143145, 500) Shape of issue bodies tensor (143145, 15)
num_words = len(word_index)+1
word2Vec_embedding_matrix = np.zeros((num_words, embedding_dims))
for word, i in word_index.items():
if i > num_words:
continue
word2Vec_embedding_vector = word2Vec_embeddings_index.get(word)
if word2Vec_embedding_vector is not None:
#words not found in embedding index will be all-zeros.
word2Vec_embedding_matrix[i] = word2Vec_embedding_vector
print(num_words)
print(word2Vec_embedding_matrix.shape[0])
print(word2Vec_embedding_matrix.shape[1])
792008 792008 128
#1 Convolutional Neural Network (CNN) with Word2Vec
CNN_Word2Vec_model = Sequential([
Embedding(input_dim =word2Vec_embedding_matrix.shape[0], input_length=max_len, output_dim=word2Vec_embedding_matrix.shape[1],weights=[word2Vec_embedding_matrix], trainable=False),
SpatialDropout1D(0.5),
# ... 100 filters with a kernel size of 4 so that each convolution will consider a window of 4 word embeddings
Conv1D(filters=100, kernel_size=4, padding='same', activation='relu'),
#**batch normalization layer** normalizes the activations of the previous layer at each batch,
#i.e. applies a transformation that maintains the mean activation close to 0 and the activation standard deviation close to 1.
#It will be added after the activation function between a convolutional and a max-pooling layer.
BatchNormalization(),
GlobalMaxPool1D(),
Dropout(0.5),
Dense(50, activation = 'relu'),
Dense(15, activation = 'sigmoid')
])
CNN_Word2Vec_model.compile(loss='binary_crossentropy', optimizer=Adam(0.01), metrics=['accuracy', mean_pred, fmeasure, precision, recall])
CNN_Word2Vec_model.summary()
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding (Embedding) (None, 500, 128) 101377024
spatial_dropout1d (SpatialD (None, 500, 128) 0
ropout1D)
conv1d (Conv1D) (None, 500, 100) 51300
batch_normalization (BatchN (None, 500, 100) 400
ormalization)
global_max_pooling1d (Globa (None, 100) 0
lMaxPooling1D)
dropout (Dropout) (None, 100) 0
dense (Dense) (None, 50) 5050
dense_1 (Dense) (None, 15) 765
=================================================================
Total params: 101,434,539
Trainable params: 57,315
Non-trainable params: 101,377,224
_________________________________________________________________
#plot the CNN_GLove model architecture
#plot_model(CNN_Glove_model, to_file='CNN_Glove_model_plot.png', show_shapes=True, show_layer_names=True)
#Image(retina=True, filename='CNN_Glove_model_plot.png')
CNN_Word2Vec_model_fit = CNN_Word2Vec_model.fit(X_tra, y_tra, batch_size=batch_size2, epochs=num_epochs, validation_data=(X_val, y_val))
Epoch 1/15 504/504 [==============================] - 196s 384ms/step - loss: 0.2096 - accuracy: 0.5020 - mean_pred: 0.0856 - fmeasure: 0.3431 - precision: 0.6042 - recall: 0.2472 - val_loss: 0.1847 - val_accuracy: 0.5776 - val_mean_pred: 0.0862 - val_fmeasure: 0.3810 - val_precision: 0.8247 - val_recall: 0.2481 Epoch 2/15 504/504 [==============================] - 193s 382ms/step - loss: 0.1830 - accuracy: 0.5578 - mean_pred: 0.0820 - fmeasure: 0.4337 - precision: 0.7024 - recall: 0.3147 - val_loss: 0.1783 - val_accuracy: 0.5922 - val_mean_pred: 0.0889 - val_fmeasure: 0.4846 - val_precision: 0.7308 - val_recall: 0.3629 Epoch 3/15 504/504 [==============================] - 193s 382ms/step - loss: 0.1785 - accuracy: 0.5746 - mean_pred: 0.0814 - fmeasure: 0.4673 - precision: 0.7019 - recall: 0.3510 - val_loss: 0.1723 - val_accuracy: 0.6061 - val_mean_pred: 0.0854 - val_fmeasure: 0.5081 - val_precision: 0.7258 - val_recall: 0.3912 Epoch 4/15 504/504 [==============================] - 192s 381ms/step - loss: 0.1762 - accuracy: 0.5851 - mean_pred: 0.0812 - fmeasure: 0.4840 - precision: 0.7012 - recall: 0.3705 - val_loss: 0.1705 - val_accuracy: 0.6106 - val_mean_pred: 0.0820 - val_fmeasure: 0.5100 - val_precision: 0.7310 - val_recall: 0.3920 Epoch 5/15 504/504 [==============================] - 195s 387ms/step - loss: 0.1744 - accuracy: 0.5902 - mean_pred: 0.0810 - fmeasure: 0.4954 - precision: 0.6997 - recall: 0.3842 - val_loss: 0.1701 - val_accuracy: 0.6082 - val_mean_pred: 0.0838 - val_fmeasure: 0.5252 - val_precision: 0.7134 - val_recall: 0.4160 Epoch 6/15 504/504 [==============================] - 192s 381ms/step - loss: 0.1731 - accuracy: 0.5948 - mean_pred: 0.0809 - fmeasure: 0.5040 - precision: 0.6988 - recall: 0.3952 - val_loss: 0.1671 - val_accuracy: 0.6246 - val_mean_pred: 0.0839 - val_fmeasure: 0.5414 - val_precision: 0.7249 - val_recall: 0.4323 Epoch 7/15 504/504 [==============================] - 193s 383ms/step - loss: 0.1714 - accuracy: 0.5968 - mean_pred: 0.0809 - fmeasure: 0.5114 - precision: 0.7011 - recall: 0.4035 - val_loss: 0.1679 - val_accuracy: 0.6123 - val_mean_pred: 0.0828 - val_fmeasure: 0.5528 - val_precision: 0.6858 - val_recall: 0.4633 Epoch 8/15 504/504 [==============================] - 193s 382ms/step - loss: 0.1708 - accuracy: 0.5991 - mean_pred: 0.0809 - fmeasure: 0.5095 - precision: 0.7087 - recall: 0.3995 - val_loss: 0.1656 - val_accuracy: 0.6226 - val_mean_pred: 0.0832 - val_fmeasure: 0.5384 - val_precision: 0.7340 - val_recall: 0.4254 Epoch 9/15 504/504 [==============================] - 193s 384ms/step - loss: 0.1703 - accuracy: 0.6017 - mean_pred: 0.0808 - fmeasure: 0.5137 - precision: 0.7104 - recall: 0.4036 - val_loss: 0.1647 - val_accuracy: 0.6185 - val_mean_pred: 0.0827 - val_fmeasure: 0.5511 - val_precision: 0.7213 - val_recall: 0.4462 Epoch 10/15 504/504 [==============================] - 194s 385ms/step - loss: 0.1697 - accuracy: 0.6028 - mean_pred: 0.0808 - fmeasure: 0.5156 - precision: 0.7132 - recall: 0.4049 - val_loss: 0.1668 - val_accuracy: 0.6150 - val_mean_pred: 0.0827 - val_fmeasure: 0.5152 - val_precision: 0.7582 - val_recall: 0.3906 Epoch 11/15 504/504 [==============================] - 193s 383ms/step - loss: 0.1694 - accuracy: 0.6049 - mean_pred: 0.0808 - fmeasure: 0.5157 - precision: 0.7164 - recall: 0.4043 - val_loss: 0.1670 - val_accuracy: 0.6122 - val_mean_pred: 0.0837 - val_fmeasure: 0.5479 - val_precision: 0.6945 - val_recall: 0.4526 Epoch 12/15 504/504 [==============================] - 193s 384ms/step - loss: 0.1691 - accuracy: 0.6046 - mean_pred: 0.0808 - fmeasure: 0.5155 - precision: 0.7162 - recall: 0.4038 - val_loss: 0.1642 - val_accuracy: 0.6234 - val_mean_pred: 0.0842 - val_fmeasure: 0.5393 - val_precision: 0.7457 - val_recall: 0.4227 Epoch 13/15 504/504 [==============================] - 194s 384ms/step - loss: 0.1687 - accuracy: 0.6053 - mean_pred: 0.0808 - fmeasure: 0.5157 - precision: 0.7175 - recall: 0.4042 - val_loss: 0.1639 - val_accuracy: 0.6210 - val_mean_pred: 0.0833 - val_fmeasure: 0.5482 - val_precision: 0.7273 - val_recall: 0.4403 Epoch 14/15 504/504 [==============================] - 194s 386ms/step - loss: 0.1686 - accuracy: 0.6065 - mean_pred: 0.0808 - fmeasure: 0.5161 - precision: 0.7173 - recall: 0.4043 - val_loss: 0.1632 - val_accuracy: 0.6217 - val_mean_pred: 0.0810 - val_fmeasure: 0.5619 - val_precision: 0.7117 - val_recall: 0.4645 Epoch 15/15 504/504 [==============================] - 194s 385ms/step - loss: 0.1683 - accuracy: 0.6075 - mean_pred: 0.0808 - fmeasure: 0.5153 - precision: 0.7197 - recall: 0.4026 - val_loss: 0.1629 - val_accuracy: 0.6307 - val_mean_pred: 0.0818 - val_fmeasure: 0.5357 - val_precision: 0.7544 - val_recall: 0.4157
# Plot training & validation accuracy values
plt.plot(CNN_Word2Vec_model_fit.history['accuracy'])
plt.plot(CNN_Word2Vec_model_fit.history['val_accuracy'])
plt.title('CNN-Word2Vec Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Training Accuracy', 'Validation Accuracy'], loc='upper left')
plt.show()
# Plot training & validation loss values
plt.plot(CNN_Word2Vec_model_fit.history['loss'])
plt.plot(CNN_Word2Vec_model_fit.history['val_loss'])
plt.title('CNN-Word2Vec Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Training Loss', 'Validation Loss'], loc='lower right')
plt.show()
#2 Recurrent Neural Network (RNN) with Word2Vec
RNN_Word2Vec_model = Sequential([
Embedding(input_dim =word2Vec_embedding_matrix.shape[0], input_length=max_len, output_dim=word2Vec_embedding_matrix.shape[1],weights=[word2Vec_embedding_matrix], trainable=False),
SpatialDropout1D(0.5),
#Fully-connected RNN where the output is to be fed back to input.
SimpleRNN(25, return_sequences=True),
#**batch normalization layer** normalizes the activations of the previous layer at each batch,
#i.e. applies a transformation that maintains the mean activation close to 0 and the activation standard deviation close to 1.
BatchNormalization(),
Dropout(0.5),
GlobalMaxPool1D(),
Dense(50, activation = 'relu'),
Dense(15, activation = 'sigmoid')
])
#Customized the evaluation to analyse the model in terms of accuracy and mean value accuracy
RNN_Word2Vec_model.compile(loss='binary_crossentropy', optimizer=Adam(0.01), metrics=['accuracy', mean_pred, fmeasure, precision, recall])
RNN_Word2Vec_model.summary()
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_1 (Embedding) (None, 500, 128) 101377024
spatial_dropout1d_1 (Spatia (None, 500, 128) 0
lDropout1D)
simple_rnn (SimpleRNN) (None, 500, 25) 3850
batch_normalization_1 (Batc (None, 500, 25) 100
hNormalization)
dropout_1 (Dropout) (None, 500, 25) 0
global_max_pooling1d_1 (Glo (None, 25) 0
balMaxPooling1D)
dense_2 (Dense) (None, 50) 1300
dense_3 (Dense) (None, 15) 765
=================================================================
Total params: 101,383,039
Trainable params: 5,965
Non-trainable params: 101,377,074
_________________________________________________________________
RNN_Word2Vec_model_fit = RNN_Word2Vec_model.fit(X_tra, y_tra, batch_size=batch_size2, epochs=num_epochs, validation_data=(X_val, y_val))
Epoch 1/15 504/504 [==============================] - 120s 234ms/step - loss: 0.2046 - accuracy: 0.4906 - mean_pred: 0.0831 - fmeasure: 0.2680 - precision: 0.4693 - recall: 0.2240 - val_loss: 0.2363 - val_accuracy: 0.4451 - val_mean_pred: 0.1487 - val_fmeasure: 5.6773e-04 - val_precision: 0.0804 - val_recall: 2.8496e-04 Epoch 2/15 504/504 [==============================] - 119s 237ms/step - loss: 0.1942 - accuracy: 0.4985 - mean_pred: 0.0810 - fmeasure: 0.3335 - precision: 0.6093 - recall: 0.2342 - val_loss: 0.2281 - val_accuracy: 0.5117 - val_mean_pred: 0.1447 - val_fmeasure: 0.3412 - val_precision: 0.7230 - val_recall: 0.2236 Epoch 3/15 504/504 [==============================] - 118s 233ms/step - loss: 0.1922 - accuracy: 0.4980 - mean_pred: 0.0809 - fmeasure: 0.3163 - precision: 0.6711 - recall: 0.2101 - val_loss: 0.2157 - val_accuracy: 0.5335 - val_mean_pred: 0.1303 - val_fmeasure: 0.3526 - val_precision: 0.7237 - val_recall: 0.2335 Epoch 4/15 504/504 [==============================] - 117s 233ms/step - loss: 0.1911 - accuracy: 0.4972 - mean_pred: 0.0809 - fmeasure: 0.3486 - precision: 0.6635 - recall: 0.2387 - val_loss: 0.2090 - val_accuracy: 0.5313 - val_mean_pred: 0.1213 - val_fmeasure: 0.3357 - val_precision: 0.7606 - val_recall: 0.2158 Epoch 5/15 504/504 [==============================] - 118s 234ms/step - loss: 0.1902 - accuracy: 0.5004 - mean_pred: 0.0809 - fmeasure: 0.3566 - precision: 0.6662 - recall: 0.2458 - val_loss: 0.2142 - val_accuracy: 0.5348 - val_mean_pred: 0.1295 - val_fmeasure: 0.3720 - val_precision: 0.7256 - val_recall: 0.2505 Epoch 6/15 504/504 [==============================] - 119s 236ms/step - loss: 0.1898 - accuracy: 0.5034 - mean_pred: 0.0809 - fmeasure: 0.3512 - precision: 0.6781 - recall: 0.2394 - val_loss: 0.2058 - val_accuracy: 0.5322 - val_mean_pred: 0.1165 - val_fmeasure: 0.3290 - val_precision: 0.7823 - val_recall: 0.2088 Epoch 7/15 504/504 [==============================] - 119s 236ms/step - loss: 0.1892 - accuracy: 0.5057 - mean_pred: 0.0808 - fmeasure: 0.3598 - precision: 0.6767 - recall: 0.2470 - val_loss: 0.2007 - val_accuracy: 0.5344 - val_mean_pred: 0.1103 - val_fmeasure: 0.3782 - val_precision: 0.7237 - val_recall: 0.2563 Epoch 8/15 504/504 [==============================] - 121s 240ms/step - loss: 0.1892 - accuracy: 0.5013 - mean_pred: 0.0809 - fmeasure: 0.3606 - precision: 0.6826 - recall: 0.2461 - val_loss: 0.2013 - val_accuracy: 0.5336 - val_mean_pred: 0.1113 - val_fmeasure: 0.3235 - val_precision: 0.7956 - val_recall: 0.2034 Epoch 9/15 504/504 [==============================] - 122s 241ms/step - loss: 0.1890 - accuracy: 0.5047 - mean_pred: 0.0809 - fmeasure: 0.3589 - precision: 0.6861 - recall: 0.2439 - val_loss: 0.1972 - val_accuracy: 0.5201 - val_mean_pred: 0.1027 - val_fmeasure: 0.3889 - val_precision: 0.7202 - val_recall: 0.2669 Epoch 10/15 504/504 [==============================] - 123s 244ms/step - loss: 0.1884 - accuracy: 0.5086 - mean_pred: 0.0808 - fmeasure: 0.3617 - precision: 0.6933 - recall: 0.2452 - val_loss: 0.1963 - val_accuracy: 0.5316 - val_mean_pred: 0.1026 - val_fmeasure: 0.3428 - val_precision: 0.7732 - val_recall: 0.2207 Epoch 11/15 504/504 [==============================] - 123s 243ms/step - loss: 0.1882 - accuracy: 0.5160 - mean_pred: 0.0809 - fmeasure: 0.3554 - precision: 0.7023 - recall: 0.2385 - val_loss: 0.1952 - val_accuracy: 0.5295 - val_mean_pred: 0.0975 - val_fmeasure: 0.2772 - val_precision: 0.8280 - val_recall: 0.1668 Epoch 12/15 504/504 [==============================] - 122s 242ms/step - loss: 0.1878 - accuracy: 0.5185 - mean_pred: 0.0808 - fmeasure: 0.3579 - precision: 0.7027 - recall: 0.2408 - val_loss: 0.1947 - val_accuracy: 0.5454 - val_mean_pred: 0.1029 - val_fmeasure: 0.3833 - val_precision: 0.7374 - val_recall: 0.2594 Epoch 13/15 504/504 [==============================] - 123s 243ms/step - loss: 0.1884 - accuracy: 0.5156 - mean_pred: 0.0810 - fmeasure: 0.3600 - precision: 0.6988 - recall: 0.2434 - val_loss: 0.2023 - val_accuracy: 0.5278 - val_mean_pred: 0.1070 - val_fmeasure: 0.2587 - val_precision: 0.8316 - val_recall: 0.1536 Epoch 14/15 504/504 [==============================] - 123s 243ms/step - loss: 0.1874 - accuracy: 0.5193 - mean_pred: 0.0808 - fmeasure: 0.3616 - precision: 0.7038 - recall: 0.2448 - val_loss: 0.1970 - val_accuracy: 0.5473 - val_mean_pred: 0.0983 - val_fmeasure: 0.3439 - val_precision: 0.7792 - val_recall: 0.2212 Epoch 15/15 504/504 [==============================] - 123s 244ms/step - loss: 0.1869 - accuracy: 0.5191 - mean_pred: 0.0808 - fmeasure: 0.3712 - precision: 0.7024 - recall: 0.2534 - val_loss: 0.1962 - val_accuracy: 0.5527 - val_mean_pred: 0.1026 - val_fmeasure: 0.3462 - val_precision: 0.7563 - val_recall: 0.2253
# Plot training & validation accuracy values
plt.plot(RNN_Word2Vec_model_fit.history['accuracy'])
plt.plot(RNN_Word2Vec_model_fit.history['val_accuracy'])
plt.title('RNN-Word2Vec Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Training Accuracy', 'Validation Accuracy'], loc='upper left')
plt.show()
# Plot training & validation loss values
plt.plot(RNN_Word2Vec_model_fit.history['loss'])
plt.plot(RNN_Word2Vec_model_fit.history['val_loss'])
plt.title('RNN-Word2Vec Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Training Loss', 'Validation Loss'], loc='lower right')
plt.show()
#3 LSTM with Word2Vec
LSTM_Word2Vec_model = Sequential([
Embedding(input_dim =word2Vec_embedding_matrix.shape[0], input_length=max_len, output_dim=word2Vec_embedding_matrix.shape[1],weights=[word2Vec_embedding_matrix], trainable=False),
SpatialDropout1D(0.5),
#Bidirectional layer will enable our model to predict a missing word in a sequence,
#So, using this feature will enable the model to look at the context on both the left and the right.
LSTM(25, return_sequences=True),
#**batch normalization layer** normalizes the activations of the previous layer at each batch,
#i.e. applies a transformation that maintains the mean activation close to 0 and the activation standard deviation close to 1.
BatchNormalization(),
Dropout(0.5),
GlobalMaxPool1D(),
Dense(50, activation = 'relu'),
Dense(15, activation = 'sigmoid')
])
2023-04-01 14:20:17.769342: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 14:20:17.772055: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 14:20:17.774951: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
LSTM_Word2Vec_model.compile(loss='binary_crossentropy', optimizer=Adam(0.01), metrics=['accuracy', mean_pred, fmeasure, precision, recall])
LSTM_Word2Vec_model.summary()
Model: "sequential_2"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_2 (Embedding) (None, 500, 128) 101377024
spatial_dropout1d_2 (Spatia (None, 500, 128) 0
lDropout1D)
lstm (LSTM) (None, 500, 25) 15400
batch_normalization_2 (Batc (None, 500, 25) 100
hNormalization)
dropout_2 (Dropout) (None, 500, 25) 0
global_max_pooling1d_2 (Glo (None, 25) 0
balMaxPooling1D)
dense_4 (Dense) (None, 50) 1300
dense_5 (Dense) (None, 15) 765
=================================================================
Total params: 101,394,589
Trainable params: 17,515
Non-trainable params: 101,377,074
_________________________________________________________________
LSTM_Word2Vec_model_fit = LSTM_Word2Vec_model.fit(X_tra, y_tra, batch_size=batch_size2, epochs=num_epochs, validation_data=(X_val, y_val))
Epoch 1/15
2023-04-01 14:20:18.235328: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 14:20:18.237585: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 14:20:18.239274: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 14:20:19.831863: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 14:20:19.835196: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 14:20:19.837245: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
504/504 [==============================] - ETA: 0s - loss: 0.1988 - accuracy: 0.5127 - mean_pred: 0.0825 - fmeasure: 0.3637 - precision: 0.6418 - recall: 0.2602
2023-04-01 14:23:24.483383: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 14:23:24.485861: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 14:23:24.487887: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
504/504 [==============================] - 197s 383ms/step - loss: 0.1988 - accuracy: 0.5127 - mean_pred: 0.0825 - fmeasure: 0.3637 - precision: 0.6418 - recall: 0.2602 - val_loss: 0.2359 - val_accuracy: 0.5587 - val_mean_pred: 0.1677 - val_fmeasure: 0.4506 - val_precision: 0.6916 - val_recall: 0.3345 Epoch 2/15 504/504 [==============================] - 196s 388ms/step - loss: 0.1826 - accuracy: 0.5480 - mean_pred: 0.0811 - fmeasure: 0.4234 - precision: 0.6925 - recall: 0.3064 - val_loss: 0.2152 - val_accuracy: 0.5762 - val_mean_pred: 0.1449 - val_fmeasure: 0.4236 - val_precision: 0.7584 - val_recall: 0.2943 Epoch 3/15 504/504 [==============================] - 205s 407ms/step - loss: 0.1796 - accuracy: 0.5640 - mean_pred: 0.0810 - fmeasure: 0.4478 - precision: 0.6935 - recall: 0.3316 - val_loss: 0.2030 - val_accuracy: 0.5909 - val_mean_pred: 0.1322 - val_fmeasure: 0.4678 - val_precision: 0.7328 - val_recall: 0.3439 Epoch 4/15 504/504 [==============================] - 208s 412ms/step - loss: 0.1777 - accuracy: 0.5736 - mean_pred: 0.0810 - fmeasure: 0.4610 - precision: 0.6973 - recall: 0.3452 - val_loss: 0.2069 - val_accuracy: 0.5933 - val_mean_pred: 0.1393 - val_fmeasure: 0.4927 - val_precision: 0.7180 - val_recall: 0.3754 Epoch 5/15 504/504 [==============================] - 209s 415ms/step - loss: 0.1764 - accuracy: 0.5786 - mean_pred: 0.0810 - fmeasure: 0.4706 - precision: 0.7003 - recall: 0.3555 - val_loss: 0.2008 - val_accuracy: 0.5708 - val_mean_pred: 0.1261 - val_fmeasure: 0.4940 - val_precision: 0.6727 - val_recall: 0.3907 Epoch 6/15 504/504 [==============================] - 214s 424ms/step - loss: 0.1756 - accuracy: 0.5835 - mean_pred: 0.0810 - fmeasure: 0.4749 - precision: 0.7030 - recall: 0.3597 - val_loss: 0.1875 - val_accuracy: 0.5920 - val_mean_pred: 0.1089 - val_fmeasure: 0.4892 - val_precision: 0.7219 - val_recall: 0.3703 Epoch 7/15 504/504 [==============================] - 204s 404ms/step - loss: 0.1748 - accuracy: 0.5845 - mean_pred: 0.0810 - fmeasure: 0.4799 - precision: 0.7055 - recall: 0.3646 - val_loss: 0.1868 - val_accuracy: 0.5955 - val_mean_pred: 0.1061 - val_fmeasure: 0.4563 - val_precision: 0.7587 - val_recall: 0.3266 Epoch 8/15 504/504 [==============================] - 208s 413ms/step - loss: 0.1744 - accuracy: 0.5853 - mean_pred: 0.0809 - fmeasure: 0.4796 - precision: 0.7072 - recall: 0.3637 - val_loss: 0.1846 - val_accuracy: 0.5964 - val_mean_pred: 0.1029 - val_fmeasure: 0.5021 - val_precision: 0.7100 - val_recall: 0.3887 Epoch 9/15 504/504 [==============================] - 208s 413ms/step - loss: 0.1739 - accuracy: 0.5872 - mean_pred: 0.0809 - fmeasure: 0.4814 - precision: 0.7082 - recall: 0.3653 - val_loss: 0.1858 - val_accuracy: 0.5782 - val_mean_pred: 0.0977 - val_fmeasure: 0.4676 - val_precision: 0.7097 - val_recall: 0.3492 Epoch 10/15 504/504 [==============================] - 211s 418ms/step - loss: 0.1735 - accuracy: 0.5886 - mean_pred: 0.0809 - fmeasure: 0.4879 - precision: 0.7076 - recall: 0.3731 - val_loss: 0.1808 - val_accuracy: 0.6035 - val_mean_pred: 0.0919 - val_fmeasure: 0.4972 - val_precision: 0.7172 - val_recall: 0.3809 Epoch 11/15 504/504 [==============================] - 203s 403ms/step - loss: 0.1733 - accuracy: 0.5855 - mean_pred: 0.0808 - fmeasure: 0.4874 - precision: 0.7084 - recall: 0.3722 - val_loss: 0.1820 - val_accuracy: 0.6003 - val_mean_pred: 0.0923 - val_fmeasure: 0.5047 - val_precision: 0.7128 - val_recall: 0.3911 Epoch 12/15 504/504 [==============================] - 203s 403ms/step - loss: 0.1729 - accuracy: 0.5892 - mean_pred: 0.0809 - fmeasure: 0.4898 - precision: 0.7110 - recall: 0.3745 - val_loss: 0.1834 - val_accuracy: 0.5929 - val_mean_pred: 0.0882 - val_fmeasure: 0.4864 - val_precision: 0.7116 - val_recall: 0.3699 Epoch 13/15 504/504 [==============================] - 193s 384ms/step - loss: 0.1726 - accuracy: 0.5893 - mean_pred: 0.0808 - fmeasure: 0.4886 - precision: 0.7121 - recall: 0.3727 - val_loss: 0.1856 - val_accuracy: 0.5841 - val_mean_pred: 0.0873 - val_fmeasure: 0.4994 - val_precision: 0.6685 - val_recall: 0.3989 Epoch 14/15 504/504 [==============================] - 196s 389ms/step - loss: 0.1726 - accuracy: 0.5887 - mean_pred: 0.0809 - fmeasure: 0.4911 - precision: 0.7103 - recall: 0.3762 - val_loss: 0.1863 - val_accuracy: 0.5863 - val_mean_pred: 0.0867 - val_fmeasure: 0.4951 - val_precision: 0.6654 - val_recall: 0.3945 Epoch 15/15 504/504 [==============================] - 193s 383ms/step - loss: 0.1724 - accuracy: 0.5906 - mean_pred: 0.0809 - fmeasure: 0.4938 - precision: 0.7101 - recall: 0.3793 - val_loss: 0.1884 - val_accuracy: 0.5748 - val_mean_pred: 0.0848 - val_fmeasure: 0.4881 - val_precision: 0.6581 - val_recall: 0.3882
### Plot Training & Validation Accuracy with the Loss values of the LSTM-Word2Vec Model# Plot training & validation accuracy values
plt.plot(LSTM_Word2Vec_model_fit.history['accuracy'])
plt.plot(LSTM_Word2Vec_model_fit.history['val_accuracy'])
plt.title('LSTM-Word2Vec Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Training Accuracy', 'Validation Accuracy'], loc='upper left')
plt.show()
# Plot training & validation loss values
plt.plot(LSTM_Word2Vec_model_fit.history['loss'])
plt.plot(LSTM_Word2Vec_model_fit.history['val_loss'])
plt.title('LSTM-Word2Vec Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Training Loss', 'Validation Loss'], loc='lower right')
plt.show()
#4 Bidirecitional LSTM with Word2Vec
Bil_LSTM_Word2Vec_model = Sequential([
Embedding(input_dim =word2Vec_embedding_matrix.shape[0], input_length=max_len, output_dim=word2Vec_embedding_matrix.shape[1],weights=[word2Vec_embedding_matrix], trainable=False),
SpatialDropout1D(0.5),
#Bidirectional layer will enable our model to predict a missing word in a sequence,
#So, using this feature will enable the model to look at the context on both the left and the right.
Bidirectional(LSTM(25, return_sequences=True)),
#**batch normalization layer** normalizes the activations of the previous layer at each batch,
#i.e. applies a transformation that maintains the mean activation close to 0 and the activation standard deviation close to 1.
BatchNormalization(),
Dropout(0.5),
GlobalMaxPool1D(),
Dense(50, activation = 'relu'),
Dense(15, activation = 'sigmoid')
])
2023-04-01 15:11:07.877816: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:11:07.879878: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:11:07.881476: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 15:11:08.123973: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis' with dtype int32 and shape [1]
[[{{node gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis}}]]
2023-04-01 15:11:08.229214: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:11:08.232088: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:11:08.234757: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
Bil_LSTM_Word2Vec_model.compile(loss='binary_crossentropy', optimizer=Adam(0.01), metrics=['accuracy', mean_pred, fmeasure, precision, recall])
Bil_LSTM_Word2Vec_model.summary()
Model: "sequential_3"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_3 (Embedding) (None, 500, 128) 101377024
spatial_dropout1d_3 (Spatia (None, 500, 128) 0
lDropout1D)
bidirectional (Bidirectiona (None, 500, 50) 30800
l)
batch_normalization_3 (Batc (None, 500, 50) 200
hNormalization)
dropout_3 (Dropout) (None, 500, 50) 0
global_max_pooling1d_3 (Glo (None, 50) 0
balMaxPooling1D)
dense_6 (Dense) (None, 50) 2550
dense_7 (Dense) (None, 15) 765
=================================================================
Total params: 101,411,339
Trainable params: 34,215
Non-trainable params: 101,377,124
_________________________________________________________________
Bil_LSTM_Word2Vec_model_fit = Bil_LSTM_Word2Vec_model.fit(X_tra, y_tra, batch_size=batch_size2, epochs=num_epochs, validation_data=(X_val, y_val))
Epoch 1/15
2023-04-01 15:11:16.934802: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:11:16.938003: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:11:16.939929: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 15:11:17.155771: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis' with dtype int32 and shape [1]
[[{{node gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis}}]]
2023-04-01 15:11:17.246127: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:11:17.247977: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:11:17.249551: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 15:11:18.398609: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis' with dtype int32 and shape [1]
[[{{node gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis}}]]
2023-04-01 15:11:19.386783: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:11:19.389112: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:11:19.391011: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 15:11:19.692535: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis' with dtype int32 and shape [1]
[[{{node gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis}}]]
2023-04-01 15:11:19.800033: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:11:19.802186: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:11:19.805208: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 15:11:20.842236: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis' with dtype int32 and shape [1]
[[{{node gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis}}]]
504/504 [==============================] - ETA: 0s - loss: 0.1938 - accuracy: 0.5412 - mean_pred: 0.0823 - fmeasure: 0.4170 - precision: 0.6595 - recall: 0.3099
2023-04-01 15:16:38.952156: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:16:38.953928: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:16:38.957359: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
2023-04-01 15:16:39.234623: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis' with dtype int32 and shape [1]
[[{{node gradients/ReverseV2_grad/ReverseV2/ReverseV2/axis}}]]
2023-04-01 15:16:39.324018: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_2_grad/concat/split_2/split_dim' with dtype int32
[[{{node gradients/split_2_grad/concat/split_2/split_dim}}]]
2023-04-01 15:16:39.326584: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_grad/concat/split/split_dim' with dtype int32
[[{{node gradients/split_grad/concat/split/split_dim}}]]
2023-04-01 15:16:39.329343: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'gradients/split_1_grad/concat/split_1/split_dim' with dtype int32
[[{{node gradients/split_1_grad/concat/split_1/split_dim}}]]
504/504 [==============================] - 348s 663ms/step - loss: 0.1938 - accuracy: 0.5412 - mean_pred: 0.0823 - fmeasure: 0.4170 - precision: 0.6595 - recall: 0.3099 - val_loss: 0.2222 - val_accuracy: 0.5969 - val_mean_pred: 0.1577 - val_fmeasure: 0.4971 - val_precision: 0.7101 - val_recall: 0.3828 Epoch 2/15 504/504 [==============================] - 337s 669ms/step - loss: 0.1768 - accuracy: 0.5827 - mean_pred: 0.0811 - fmeasure: 0.4760 - precision: 0.7053 - recall: 0.3604 - val_loss: 0.2070 - val_accuracy: 0.6003 - val_mean_pred: 0.1402 - val_fmeasure: 0.4766 - val_precision: 0.7386 - val_recall: 0.3522 Epoch 3/15 504/504 [==============================] - 346s 687ms/step - loss: 0.1739 - accuracy: 0.5924 - mean_pred: 0.0810 - fmeasure: 0.4923 - precision: 0.7082 - recall: 0.3782 - val_loss: 0.2052 - val_accuracy: 0.6049 - val_mean_pred: 0.1395 - val_fmeasure: 0.5077 - val_precision: 0.7227 - val_recall: 0.3918 Epoch 4/15 504/504 [==============================] - 356s 705ms/step - loss: 0.1734 - accuracy: 0.5944 - mean_pred: 0.0812 - fmeasure: 0.4994 - precision: 0.7071 - recall: 0.3870 - val_loss: 0.2014 - val_accuracy: 0.6094 - val_mean_pred: 0.1339 - val_fmeasure: 0.4906 - val_precision: 0.7409 - val_recall: 0.3672 Epoch 5/15 504/504 [==============================] - 334s 663ms/step - loss: 0.1723 - accuracy: 0.5954 - mean_pred: 0.0810 - fmeasure: 0.5023 - precision: 0.7086 - recall: 0.3900 - val_loss: 0.1972 - val_accuracy: 0.5994 - val_mean_pred: 0.1268 - val_fmeasure: 0.5081 - val_precision: 0.7166 - val_recall: 0.3940 Epoch 6/15 504/504 [==============================] - 322s 639ms/step - loss: 0.1712 - accuracy: 0.5985 - mean_pred: 0.0810 - fmeasure: 0.5081 - precision: 0.7091 - recall: 0.3969 - val_loss: 0.1835 - val_accuracy: 0.6095 - val_mean_pred: 0.1100 - val_fmeasure: 0.4887 - val_precision: 0.7506 - val_recall: 0.3626 Epoch 7/15 504/504 [==============================] - 325s 644ms/step - loss: 0.1705 - accuracy: 0.6010 - mean_pred: 0.0809 - fmeasure: 0.5098 - precision: 0.7100 - recall: 0.3985 - val_loss: 0.1845 - val_accuracy: 0.6136 - val_mean_pred: 0.1108 - val_fmeasure: 0.4741 - val_precision: 0.7786 - val_recall: 0.3413 Epoch 8/15 504/504 [==============================] - 362s 718ms/step - loss: 0.1702 - accuracy: 0.6005 - mean_pred: 0.0809 - fmeasure: 0.5107 - precision: 0.7110 - recall: 0.3998 - val_loss: 0.1793 - val_accuracy: 0.6108 - val_mean_pred: 0.1032 - val_fmeasure: 0.4841 - val_precision: 0.7608 - val_recall: 0.3554 Epoch 9/15 504/504 [==============================] - 315s 624ms/step - loss: 0.1700 - accuracy: 0.6022 - mean_pred: 0.0809 - fmeasure: 0.5141 - precision: 0.7094 - recall: 0.4039 - val_loss: 0.1813 - val_accuracy: 0.6122 - val_mean_pred: 0.1062 - val_fmeasure: 0.4875 - val_precision: 0.7662 - val_recall: 0.3579 Epoch 10/15 504/504 [==============================] - 381s 756ms/step - loss: 0.1697 - accuracy: 0.6013 - mean_pred: 0.0809 - fmeasure: 0.5127 - precision: 0.7119 - recall: 0.4016 - val_loss: 0.1786 - val_accuracy: 0.6126 - val_mean_pred: 0.1006 - val_fmeasure: 0.4632 - val_precision: 0.7889 - val_recall: 0.3283 Epoch 11/15 504/504 [==============================] - 384s 761ms/step - loss: 0.1693 - accuracy: 0.6028 - mean_pred: 0.0809 - fmeasure: 0.5138 - precision: 0.7142 - recall: 0.4021 - val_loss: 0.1769 - val_accuracy: 0.6122 - val_mean_pred: 0.0976 - val_fmeasure: 0.4853 - val_precision: 0.7691 - val_recall: 0.3549 Epoch 12/15 504/504 [==============================] - 382s 759ms/step - loss: 0.1695 - accuracy: 0.6022 - mean_pred: 0.0809 - fmeasure: 0.5144 - precision: 0.7140 - recall: 0.4030 - val_loss: 0.1766 - val_accuracy: 0.6075 - val_mean_pred: 0.0925 - val_fmeasure: 0.4687 - val_precision: 0.7785 - val_recall: 0.3356 Epoch 13/15 504/504 [==============================] - 393s 779ms/step - loss: 0.1694 - accuracy: 0.6026 - mean_pred: 0.0809 - fmeasure: 0.5146 - precision: 0.7141 - recall: 0.4030 - val_loss: 0.1792 - val_accuracy: 0.6078 - val_mean_pred: 0.0930 - val_fmeasure: 0.4477 - val_precision: 0.8021 - val_recall: 0.3108 Epoch 14/15 504/504 [==============================] - 391s 776ms/step - loss: 0.1701 - accuracy: 0.5995 - mean_pred: 0.0808 - fmeasure: 0.5082 - precision: 0.7125 - recall: 0.3960 - val_loss: 0.1786 - val_accuracy: 0.6117 - val_mean_pred: 0.0911 - val_fmeasure: 0.4619 - val_precision: 0.7809 - val_recall: 0.3283 Epoch 15/15 504/504 [==============================] - 411s 816ms/step - loss: 0.1706 - accuracy: 0.5977 - mean_pred: 0.0809 - fmeasure: 0.5077 - precision: 0.7111 - recall: 0.3957 - val_loss: 0.1773 - val_accuracy: 0.6134 - val_mean_pred: 0.0870 - val_fmeasure: 0.4788 - val_precision: 0.7616 - val_recall: 0.3495
# Plot training & validation accuracy values
plt.plot(Bil_LSTM_Word2Vec_model_fit.history['accuracy'])
plt.plot(Bil_LSTM_Word2Vec_model_fit.history['val_accuracy'])
plt.title('Bidirecitonal LSTM-Word2Vec Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Training Accuracy', 'Validation Accuracy'], loc='upper left')
plt.show()
# Plot training & validation loss values
plt.plot(Bil_LSTM_Word2Vec_model_fit.history['loss'])
plt.plot(Bil_LSTM_Word2Vec_model_fit.history['val_loss'])
plt.title('Bidirecitonal LSTM-Word2Vec Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Training Loss', 'Validation Loss'], loc='lower right')
plt.show()
#5 Gated Recurrent (GRU) with Word2Vec
sequence_input = Input(shape=(max_len, ))
model = Embedding(input_dim =word2Vec_embedding_matrix.shape[0], input_length=max_len, output_dim=word2Vec_embedding_matrix.shape[1],weights=[word2Vec_embedding_matrix], trainable=False)(sequence_input)
model = SpatialDropout1D(0.2)(model)
model = GRU(128, return_sequences=True,dropout=0.1,recurrent_dropout=0.1)(model)
model = Conv1D(64, kernel_size = 3, padding = "valid", kernel_initializer = "glorot_uniform")(model)
avg_pool = GlobalAveragePooling1D()(model)
max_pool = GlobalMaxPooling1D()(model)
model = concatenate([avg_pool, max_pool])
preds = Dense(15, activation="sigmoid")(model)
GRU_Word2Vec_model = Model(sequence_input, preds)
GRU_Word2Vec_model.compile(loss='binary_crossentropy',optimizer="Adam",metrics=['accuracy', mean_pred, fmeasure, precision, recall])
GRU_Word2Vec_model.summary()
Model: "model_1" __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ================================================================================================== Total params: 101,502,671 Trainable params: 125,647 Non-trainable params: 101,377,024 __________________________________________________________________________________________________
GRU_Word2Vec_model_fit = GRU_Word2Vec_model.fit(X_tra, y_tra, batch_size=batch_size2, epochs=num_epochs, validation_data=(X_val, y_val))
Epoch 1/15 504/504 [==============================] - 792s 2s/step - loss: 0.1808 - accuracy: 0.5891 - mean_pred: 0.0858 - fmeasure: 0.4800 - precision: 0.7235 - recall: 0.3649 - val_loss: 0.1645 - val_accuracy: 0.6307 - val_mean_pred: 0.0830 - val_fmeasure: 0.5487 - val_precision: 0.7406 - val_recall: 0.4362 Epoch 2/15 504/504 [==============================] - 864s 2s/step - loss: 0.1597 - accuracy: 0.6432 - mean_pred: 0.0809 - fmeasure: 0.5543 - precision: 0.7557 - recall: 0.4387 - val_loss: 0.1593 - val_accuracy: 0.6504 - val_mean_pred: 0.0752 - val_fmeasure: 0.5609 - val_precision: 0.7648 - val_recall: 0.4433 Epoch 3/15 504/504 [==============================] - 1055s 2s/step - loss: 0.1539 - accuracy: 0.6595 - mean_pred: 0.0809 - fmeasure: 0.5784 - precision: 0.7641 - recall: 0.4661 - val_loss: 0.1549 - val_accuracy: 0.6623 - val_mean_pred: 0.0775 - val_fmeasure: 0.5805 - val_precision: 0.7620 - val_recall: 0.4694 Epoch 4/15 504/504 [==============================] - 913s 2s/step - loss: 0.1495 - accuracy: 0.6719 - mean_pred: 0.0808 - fmeasure: 0.5954 - precision: 0.7724 - recall: 0.4853 - val_loss: 0.1530 - val_accuracy: 0.6683 - val_mean_pred: 0.0811 - val_fmeasure: 0.5848 - val_precision: 0.7747 - val_recall: 0.4702 Epoch 5/15 504/504 [==============================] - 898s 2s/step - loss: 0.1457 - accuracy: 0.6828 - mean_pred: 0.0808 - fmeasure: 0.6098 - precision: 0.7791 - recall: 0.5017 - val_loss: 0.1512 - val_accuracy: 0.6743 - val_mean_pred: 0.0817 - val_fmeasure: 0.6005 - val_precision: 0.7638 - val_recall: 0.4952 Epoch 6/15 504/504 [==============================] - 891s 2s/step - loss: 0.1422 - accuracy: 0.6917 - mean_pred: 0.0808 - fmeasure: 0.6222 - precision: 0.7869 - recall: 0.5152 - val_loss: 0.1514 - val_accuracy: 0.6733 - val_mean_pred: 0.0832 - val_fmeasure: 0.6152 - val_precision: 0.7446 - val_recall: 0.5245 Epoch 7/15 504/504 [==============================] - 834s 2s/step - loss: 0.1393 - accuracy: 0.6991 - mean_pred: 0.0808 - fmeasure: 0.6328 - precision: 0.7918 - recall: 0.5276 - val_loss: 0.1516 - val_accuracy: 0.6715 - val_mean_pred: 0.0823 - val_fmeasure: 0.6044 - val_precision: 0.7633 - val_recall: 0.5007 Epoch 8/15 504/504 [==============================] - 806s 2s/step - loss: 0.1365 - accuracy: 0.7058 - mean_pred: 0.0808 - fmeasure: 0.6428 - precision: 0.7985 - recall: 0.5386 - val_loss: 0.1500 - val_accuracy: 0.6782 - val_mean_pred: 0.0820 - val_fmeasure: 0.6141 - val_precision: 0.7635 - val_recall: 0.5140 Epoch 9/15 504/504 [==============================] - 847s 2s/step - loss: 0.1339 - accuracy: 0.7111 - mean_pred: 0.0808 - fmeasure: 0.6493 - precision: 0.8013 - recall: 0.5464 - val_loss: 0.1507 - val_accuracy: 0.6750 - val_mean_pred: 0.0813 - val_fmeasure: 0.6178 - val_precision: 0.7556 - val_recall: 0.5229 Epoch 10/15 504/504 [==============================] - 789s 2s/step - loss: 0.1310 - accuracy: 0.7186 - mean_pred: 0.0808 - fmeasure: 0.6594 - precision: 0.8078 - recall: 0.5577 - val_loss: 0.1516 - val_accuracy: 0.6750 - val_mean_pred: 0.0838 - val_fmeasure: 0.6269 - val_precision: 0.7369 - val_recall: 0.5457 Epoch 11/15 504/504 [==============================] - 770s 2s/step - loss: 0.1284 - accuracy: 0.7256 - mean_pred: 0.0808 - fmeasure: 0.6683 - precision: 0.8125 - recall: 0.5681 - val_loss: 0.1522 - val_accuracy: 0.6734 - val_mean_pred: 0.0820 - val_fmeasure: 0.6171 - val_precision: 0.7463 - val_recall: 0.5263 Epoch 12/15 504/504 [==============================] - 771s 2s/step - loss: 0.1260 - accuracy: 0.7299 - mean_pred: 0.0807 - fmeasure: 0.6757 - precision: 0.8181 - recall: 0.5762 - val_loss: 0.1543 - val_accuracy: 0.6720 - val_mean_pred: 0.0810 - val_fmeasure: 0.6167 - val_precision: 0.7413 - val_recall: 0.5282 Epoch 13/15 504/504 [==============================] - 766s 2s/step - loss: 0.1235 - accuracy: 0.7357 - mean_pred: 0.0808 - fmeasure: 0.6828 - precision: 0.8221 - recall: 0.5845 - val_loss: 0.1545 - val_accuracy: 0.6692 - val_mean_pred: 0.0828 - val_fmeasure: 0.6154 - val_precision: 0.7358 - val_recall: 0.5292 Epoch 14/15 504/504 [==============================] - 768s 2s/step - loss: 0.1213 - accuracy: 0.7422 - mean_pred: 0.0808 - fmeasure: 0.6905 - precision: 0.8271 - recall: 0.5932 - val_loss: 0.1569 - val_accuracy: 0.6648 - val_mean_pred: 0.0785 - val_fmeasure: 0.6112 - val_precision: 0.7364 - val_recall: 0.5227 Epoch 15/15 504/504 [==============================] - 774s 2s/step - loss: 0.1191 - accuracy: 0.7467 - mean_pred: 0.0807 - fmeasure: 0.6966 - precision: 0.8302 - recall: 0.6005 - val_loss: 0.1569 - val_accuracy: 0.6713 - val_mean_pred: 0.0799 - val_fmeasure: 0.6138 - val_precision: 0.7345 - val_recall: 0.5275
# Plot training & validation accuracy values
plt.plot(GRU_Word2Vec_model_fit.history['accuracy'])
plt.plot(GRU_Word2Vec_model_fit.history['val_accuracy'])
plt.title('Gated Recurrent Unit (GRU) with Word2Vec Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Training Accuracy', 'Validation Accuracy'], loc='upper left')
plt.show()
# Plot training & validation loss values
plt.plot(GRU_Word2Vec_model_fit.history['loss'])
plt.plot(GRU_Word2Vec_model_fit.history['val_loss'])
plt.title('Bidirectional Gated Recurrent Unit (GRU) with Word2Vec Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Training Loss', 'Validation Loss'], loc='lower right')
plt.show()
#6 Bidirectional Gated Recurrent (GRU) with Word2Vec
sequence_input = Input(shape=(max_len, ))
model = Embedding(input_dim =word2Vec_embedding_matrix.shape[0], input_length=max_len, output_dim=word2Vec_embedding_matrix.shape[1],weights=[word2Vec_embedding_matrix], trainable=False)(sequence_input)
model = SpatialDropout1D(0.2)(model)
model = Bidirectional(GRU(128, return_sequences=True,dropout=0.1,recurrent_dropout=0.1))(model)
model = Conv1D(64, kernel_size = 3, padding = "valid", kernel_initializer = "glorot_uniform")(model)
avg_pool = GlobalAveragePooling1D()(model)
max_pool = GlobalMaxPooling1D()(model)
model = concatenate([avg_pool, max_pool])
preds = Dense(15, activation="sigmoid")(model)
Bil_GRU_Word2Vec_model = Model(sequence_input, preds)
Bil_GRU_Word2Vec_model.compile(loss='binary_crossentropy',optimizer="Adam",metrics=['accuracy', mean_pred, fmeasure, precision, recall])
Bil_GRU_Word2Vec_model.summary()
Model: "model_3" __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ================================================================================================== Total params: 101,626,319 Trainable params: 249,295 Non-trainable params: 101,377,024 __________________________________________________________________________________________________
Bil_GRU_Word2Vec_model_fit = Bil_GRU_Word2Vec_model.fit(X_tra, y_tra, batch_size=batch_size2, epochs=num_epochs, validation_data=(X_val, y_val))
Epoch 1/15 504/504 [==============================] - 1488s 3s/step - loss: 0.1742 - accuracy: 0.6113 - mean_pred: 0.0847 - fmeasure: 0.5111 - precision: 0.7323 - recall: 0.3989 - val_loss: 0.1603 - val_accuracy: 0.6474 - val_mean_pred: 0.0824 - val_fmeasure: 0.5662 - val_precision: 0.7425 - val_recall: 0.4580 Epoch 2/15 504/504 [==============================] - 1477s 3s/step - loss: 0.1550 - accuracy: 0.6563 - mean_pred: 0.0809 - fmeasure: 0.5777 - precision: 0.7615 - recall: 0.4665 - val_loss: 0.1555 - val_accuracy: 0.6613 - val_mean_pred: 0.0813 - val_fmeasure: 0.5817 - val_precision: 0.7582 - val_recall: 0.4723 Epoch 3/15 504/504 [==============================] - 1482s 3s/step - loss: 0.1484 - accuracy: 0.6754 - mean_pred: 0.0808 - fmeasure: 0.6014 - precision: 0.7727 - recall: 0.4932 - val_loss: 0.1529 - val_accuracy: 0.6710 - val_mean_pred: 0.0787 - val_fmeasure: 0.6012 - val_precision: 0.7554 - val_recall: 0.4997 Epoch 4/15 504/504 [==============================] - 1487s 3s/step - loss: 0.1430 - accuracy: 0.6911 - mean_pred: 0.0808 - fmeasure: 0.6212 - precision: 0.7827 - recall: 0.5156 - val_loss: 0.1512 - val_accuracy: 0.6714 - val_mean_pred: 0.0809 - val_fmeasure: 0.5823 - val_precision: 0.7772 - val_recall: 0.4659 Epoch 5/15 504/504 [==============================] - 1775s 4s/step - loss: 0.1382 - accuracy: 0.7022 - mean_pred: 0.0808 - fmeasure: 0.6368 - precision: 0.7926 - recall: 0.5330 - val_loss: 0.1510 - val_accuracy: 0.6658 - val_mean_pred: 0.0817 - val_fmeasure: 0.6079 - val_precision: 0.7445 - val_recall: 0.5141 Epoch 6/15 504/504 [==============================] - 1891s 4s/step - loss: 0.1333 - accuracy: 0.7132 - mean_pred: 0.0808 - fmeasure: 0.6524 - precision: 0.8020 - recall: 0.5506 - val_loss: 0.1525 - val_accuracy: 0.6719 - val_mean_pred: 0.0762 - val_fmeasure: 0.6119 - val_precision: 0.7541 - val_recall: 0.5152 Epoch 7/15 504/504 [==============================] - 1890s 4s/step - loss: 0.1286 - accuracy: 0.7240 - mean_pred: 0.0808 - fmeasure: 0.6665 - precision: 0.8097 - recall: 0.5670 - val_loss: 0.1511 - val_accuracy: 0.6743 - val_mean_pred: 0.0803 - val_fmeasure: 0.6227 - val_precision: 0.7471 - val_recall: 0.5342 Epoch 8/15 504/504 [==============================] - 1641s 3s/step - loss: 0.1240 - accuracy: 0.7342 - mean_pred: 0.0808 - fmeasure: 0.6799 - precision: 0.8191 - recall: 0.5818 - val_loss: 0.1536 - val_accuracy: 0.6659 - val_mean_pred: 0.0789 - val_fmeasure: 0.6115 - val_precision: 0.7499 - val_recall: 0.5166 Epoch 9/15 504/504 [==============================] - 1606s 3s/step - loss: 0.1191 - accuracy: 0.7461 - mean_pred: 0.0807 - fmeasure: 0.6946 - precision: 0.8290 - recall: 0.5983 - val_loss: 0.1563 - val_accuracy: 0.6627 - val_mean_pred: 0.0843 - val_fmeasure: 0.6105 - val_precision: 0.7296 - val_recall: 0.5253 Epoch 10/15 504/504 [==============================] - 1666s 3s/step - loss: 0.1143 - accuracy: 0.7576 - mean_pred: 0.0808 - fmeasure: 0.7091 - precision: 0.8370 - recall: 0.6158 - val_loss: 0.1583 - val_accuracy: 0.6655 - val_mean_pred: 0.0806 - val_fmeasure: 0.6157 - val_precision: 0.7398 - val_recall: 0.5277 Epoch 11/15 504/504 [==============================] - 1872s 4s/step - loss: 0.1097 - accuracy: 0.7678 - mean_pred: 0.0808 - fmeasure: 0.7233 - precision: 0.8458 - recall: 0.6322 - val_loss: 0.1608 - val_accuracy: 0.6602 - val_mean_pred: 0.0807 - val_fmeasure: 0.6136 - val_precision: 0.7235 - val_recall: 0.5331 Epoch 12/15 504/504 [==============================] - 1723s 3s/step - loss: 0.1050 - accuracy: 0.7792 - mean_pred: 0.0808 - fmeasure: 0.7377 - precision: 0.8543 - recall: 0.6497 - val_loss: 0.1644 - val_accuracy: 0.6555 - val_mean_pred: 0.0803 - val_fmeasure: 0.6126 - val_precision: 0.7226 - val_recall: 0.5321 Epoch 13/15 504/504 [==============================] - 1740s 3s/step - loss: 0.1007 - accuracy: 0.7891 - mean_pred: 0.0807 - fmeasure: 0.7485 - precision: 0.8604 - recall: 0.6629 - val_loss: 0.1688 - val_accuracy: 0.6566 - val_mean_pred: 0.0783 - val_fmeasure: 0.6075 - val_precision: 0.7208 - val_recall: 0.5253 Epoch 14/15 504/504 [==============================] - 1868s 4s/step - loss: 0.0964 - accuracy: 0.7991 - mean_pred: 0.0807 - fmeasure: 0.7620 - precision: 0.8683 - recall: 0.6796 - val_loss: 0.1746 - val_accuracy: 0.6455 - val_mean_pred: 0.0832 - val_fmeasure: 0.6027 - val_precision: 0.6894 - val_recall: 0.5358 Epoch 15/15 504/504 [==============================] - 1571s 3s/step - loss: 0.0925 - accuracy: 0.8088 - mean_pred: 0.0808 - fmeasure: 0.7731 - precision: 0.8738 - recall: 0.6938 - val_loss: 0.1789 - val_accuracy: 0.6444 - val_mean_pred: 0.0791 - val_fmeasure: 0.6007 - val_precision: 0.6986 - val_recall: 0.5273
# Plot training & validation accuracy values
plt.plot(Bil_GRU_Word2Vec_model_fit.history['accuracy'])
plt.plot(Bil_GRU_Word2Vec_model_fit.history['val_accuracy'])
plt.title(' Bidirectional Gated Recurrent Unit (GRU) with Word2Vec Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Training Accuracy', 'Validation Accuracy'], loc='upper left')
plt.show()
# Plot training & validation loss values
plt.plot(Bil_GRU_Word2Vec_model_fit.history['loss'])
plt.plot(Bil_GRU_Word2Vec_model_fit.history['val_loss'])
plt.title('Bidirectional Gated Recurrent Unit (GRU) with Word2Vec Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Training Loss', 'Validation Loss'], loc='lower right')
plt.show()
from chart_studio import plotly
import plotly.offline as py
import plotly.graph_objs as go
#Computing the highest of the evaluation matrics (per model)
trace = go.Table(
header=dict(values=['Model', 'Loss', 'Accuracy', 'mean_pred', 'F-Measure', 'Precision', 'Recall'],
line = dict(color='#7D7F80'),
fill = dict(color='#a1c3d1'),
align = ['left'] * 5),
cells=dict(values=[['CNN-Word2Vec', 'RNNs-Word2Vec', 'LSTM-Word2Vec', ' BiLSTM-Word2Vec', 'GRU-Word2Vec', 'BiGRU-Word2Vec'],
[
#Loss Evaluation
round(np.max(CNN_Word2Vec_model_fit.history['loss']), 3), round(np.max(RNN_Word2Vec_model_fit.history['loss']), 3),
round(np.max(LSTM_Word2Vec_model_fit.history['loss']), 3), round(np.max(Bil_LSTM_Word2Vec_model_fit.history['loss']), 3), round(np.max(GRU_Word2Vec_model_fit.history['loss']), 3),
round(np.max(Bil_GRU_Word2Vec_model_fit.history['loss']), 3)],
#Accuracy Evaluation
[round(np.max(CNN_Word2Vec_model_fit.history['accuracy']), 3), round(np.max(RNN_Word2Vec_model_fit.history['accuracy']), 3),
round(np.max(LSTM_Word2Vec_model_fit.history['accuracy']), 3), round(np.max(Bil_LSTM_Word2Vec_model_fit.history['accuracy']), 3), round(np.max(GRU_Word2Vec_model_fit.history['accuracy']), 3),
round(np.max(Bil_GRU_Word2Vec_model_fit.history['accuracy']), 3)],
#mean_pred Evaluation
[round(np.max(CNN_Word2Vec_model_fit.history['mean_pred']), 3), round(np.max(RNN_Word2Vec_model_fit.history['mean_pred']), 3),
round(np.max(LSTM_Word2Vec_model_fit.history['mean_pred']), 3), round(np.max(Bil_LSTM_Word2Vec_model_fit.history['mean_pred']), 3), round(np.max(GRU_Word2Vec_model_fit.history['mean_pred']), 3),
round(np.max(Bil_GRU_Word2Vec_model_fit.history['mean_pred']), 3)],
#F1-Measure Evaluation fmeasure
[round(np.max(CNN_Word2Vec_model_fit.history['fmeasure']), 3), round(np.max(RNN_Word2Vec_model_fit.history['fmeasure']), 3),
round(np.max(LSTM_Word2Vec_model_fit.history['fmeasure']), 3), round(np.max(Bil_LSTM_Word2Vec_model_fit.history['fmeasure']), 3), round(np.max(GRU_Word2Vec_model_fit.history['fmeasure']), 3),
round(np.max(Bil_GRU_Word2Vec_model_fit.history['fmeasure']), 3)],
#Precision Evaluation precision
[round(np.max(CNN_Word2Vec_model_fit.history['precision']), 3), round(np.max(RNN_Word2Vec_model_fit.history['precision']), 3),
round(np.max(LSTM_Word2Vec_model_fit.history['precision']), 3), round(np.max(Bil_LSTM_Word2Vec_model_fit.history['precision']), 3), round(np.max(GRU_Word2Vec_model_fit.history['precision']), 3),
round(np.max(Bil_GRU_Word2Vec_model_fit.history['precision']), 3)],
#Recall Evaluation
[round(np.max(CNN_Word2Vec_model_fit.history['recall']), 3), round(np.max(RNN_Word2Vec_model_fit.history['recall']), 3),
round(np.max(LSTM_Word2Vec_model_fit.history['recall']), 3), round(np.max(Bil_LSTM_Word2Vec_model_fit.history['recall']), 3), round(np.max(GRU_Word2Vec_model_fit.history['recall']), 3),
round(np.max(Bil_GRU_Word2Vec_model_fit.history['recall']), 3)]
],
line = dict(color='#7D7F80'),
fill = dict(color='#EDFAFF'),
align = ['left'] * 5))
layout = dict(width=800, height=400)
data = [trace]
fig = dict(data=data, layout=layout)
py.iplot(data, filename = 'Word2Vec_trained_embedding_with the max of the evaluation matrics (per model) _table')
#Computing the mean of the evaluation matrics (per model)
trace = go.Table(
header=dict(values=['Model', 'Loss', 'Accuracy', 'mean_pred', 'F-Measure', 'Precision', 'Recall'],
line = dict(color='#7D7F80'),
fill = dict(color='#a1c3d1'),
align = ['left'] * 5),
cells=dict(values=[['CNN-Word2Vec', 'RNNs-Word2Vec', 'LSTM-Word2Vec', ' BiLSTM-Word2Vec', 'GRU-Word2Vec', 'BiGRU-Word2Vec'],
[
#Loss Evaluation
round(np.mean(CNN_Word2Vec_model_fit.history['loss']), 3), round(np.mean(RNN_Word2Vec_model_fit.history['loss']), 3),
round(np.mean(LSTM_Word2Vec_model_fit.history['loss']), 3), round(np.mean(Bil_LSTM_Word2Vec_model_fit.history['loss']), 3), round(np.mean(GRU_Word2Vec_model_fit.history['loss']), 3),
round(np.mean(Bil_GRU_Word2Vec_model_fit.history['loss']), 3)],
#Accuracy Evaluation
[round(np.mean(CNN_Word2Vec_model_fit.history['accuracy']), 3), round(np.mean(RNN_Word2Vec_model_fit.history['accuracy']), 3),
round(np.mean(LSTM_Word2Vec_model_fit.history['accuracy']), 3), round(np.mean(Bil_LSTM_Word2Vec_model_fit.history['accuracy']), 3), round(np.mean(GRU_Word2Vec_model_fit.history['accuracy']), 3),
round(np.mean(Bil_GRU_Word2Vec_model_fit.history['accuracy']), 3)],
#mean_pred Evaluation
[round(np.mean(CNN_Word2Vec_model_fit.history['mean_pred']), 3), round(np.mean(RNN_Word2Vec_model_fit.history['mean_pred']), 3),
round(np.mean(LSTM_Word2Vec_model_fit.history['mean_pred']), 3), round(np.mean(Bil_LSTM_Word2Vec_model_fit.history['mean_pred']), 3), round(np.mean(GRU_Word2Vec_model_fit.history['mean_pred']), 3),
round(np.mean(Bil_GRU_Word2Vec_model_fit.history['mean_pred']), 3)],
#F1-Measure Evaluation fmeasure
[round(np.mean(CNN_Word2Vec_model_fit.history['fmeasure']), 3), round(np.mean(RNN_Word2Vec_model_fit.history['fmeasure']), 3),
round(np.mean(LSTM_Word2Vec_model_fit.history['fmeasure']), 3), round(np.mean(Bil_LSTM_Word2Vec_model_fit.history['fmeasure']), 3), round(np.mean(GRU_Word2Vec_model_fit.history['fmeasure']), 3),
round(np.mean(Bil_GRU_Word2Vec_model_fit.history['fmeasure']), 3)],
#Precision Evaluation precision
[round(np.mean(CNN_Word2Vec_model_fit.history['precision']), 3), round(np.mean(RNN_Word2Vec_model_fit.history['precision']), 3),
round(np.mean(LSTM_Word2Vec_model_fit.history['precision']), 3), round(np.mean(Bil_LSTM_Word2Vec_model_fit.history['precision']), 3), round(np.mean(GRU_Word2Vec_model_fit.history['precision']), 3),
round(np.mean(Bil_GRU_Word2Vec_model_fit.history['precision']), 3)],
#Recall Evaluation
[round(np.mean(CNN_Word2Vec_model_fit.history['recall']), 3), round(np.mean(RNN_Word2Vec_model_fit.history['recall']), 3),
round(np.mean(LSTM_Word2Vec_model_fit.history['recall']), 3), round(np.mean(Bil_LSTM_Word2Vec_model_fit.history['recall']), 3), round(np.mean(GRU_Word2Vec_model_fit.history['recall']), 3),
round(np.mean(Bil_GRU_Word2Vec_model_fit.history['recall']), 3)]
],
line = dict(color='#7D7F80'),
fill = dict(color='#EDFAFF'),
align = ['left'] * 5))
layout = dict(width=800, height=400)
data = [trace]
fig = dict(data=data, layout=layout)
py.iplot(data, filename = 'Word2Vec_trained_embedding_with the Mean value of the evaluation matrics (per model) _table')
#Score Confusion Table
# concat all training, validation and testing accuracy scores
CNN_Word2Vec_Accuracy = ['Convolutional Neural Network (CNN) with Word2Vec',
np.max(CNN_Word2Vec_model_fit.history['accuracy']),
np.max(CNN_Word2Vec_model_fit.history['val_accuracy']),
CNN_Word2Vec_test_score[1]]
RNN_Word2Vec_Accuracy = ['Recurrent Neural Networks (RNNs) with Word2Vec',
np.max(RNN_Word2Vec_model_fit.history['accuracy']),
np.max(RNN_Word2Vec_model_fit.history['val_accuracy']),
RNN_Word2Vec_test_score[1]]
LSTM_Word2Vec_Accuracy = ['LSTM with Word2Vec',
np.max(LSTM_Word2Vec_model_fit.history['accuracy']),
np.max(LSTM_Word2Vec_model_fit.history['val_accuracy']),
LSTM_Word2Vec_test_score[1]]
Bidirectional_LSTM_Word2Vec_Accuracy = ['Bidirectional LSTM with Word2Vec',
np.max(Bil_LSTM_Word2Vec_model_fit.history['accuracy']),
np.max(Bil_LSTM_Word2Vec_model_fit.history['val_accuracy']),
Bil_LSTM_Word2Vec_test_score[1]]
GRU_Word2Vec_Accuracy = ['GRU with Word2Vec',
np.max(GRU_Word2Vec_model_fit.history['accuracy']),
np.max(GRU_Word2Vec_model_fit.history['val_accuracy']),
GRU_Word2Vec_test_score[1]]
Bidirectional_GRU_Word2Vec_Accuracy = ['Bidirectional GRU with Word2Vec',
np.max(Bil_GRU_Word2Vec_model_fit.history['accuracy']),
np.max(Bil_GRU_Word2Vec_model_fit.history['val_accuracy']),
Bil_GRU_Word2Vec_test_score[1]]
# create dataframe
experimentalResult = pd.DataFrame([CNN_Word2Vec_Accuracy])
# append all other scores
experimentalResult = experimentalResult.append([CNN_Word2Vec_Accuracy, RNN_Word2Vec_Accuracy, LSTM_Word2Vec_Accuracy, Bidirectional_LSTM_Word2Vec_Accuracy,
GRU_Word2Vec_Accuracy, Bidirectional_GRU_Word2Vec_Accuracy])
# beautify the new dataframe
experimentalResult.columns = ['Model', 'Training Accuracy', 'Validation Accuracy', 'Testing Accuracy']
experimentalResult.set_index(['Model'], inplace=True)
experimentalResult
print(experimentalResult)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /var/folders/7v/ts3m2qs15d3g15g97bgdq6lc0000gn/T/ipykernel_66251/2352390024.py in <module> 5 np.max(CNN_Word2Vec_model_fit.history['accuracy']), 6 np.max(CNN_Word2Vec_model_fit.history['val_accuracy']), ----> 7 CNN_Word2Vec_test_score[1]] 8 9 RNN_Word2Vec_Accuracy = ['Recurrent Neural Networks (RNNs) with Word2Vec', NameError: name 'CNN_Word2Vec_test_score' is not defined